home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / STRING.C < prev    next >
C/C++ Source or Header  |  1992-01-14  |  16KB  |  494 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/string.c,v 9.35 1992/01/15 04:00:20 jinx Exp $
  4.  
  5. Copyright (c) 1987-92 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* String primitives. */
  36.  
  37. #include "scheme.h"
  38. #include "prims.h"
  39.  
  40. SCHEME_OBJECT
  41. DEFUN (allocate_string, (nbytes), fast long nbytes)
  42. {
  43.   fast long count = (STRING_LENGTH_TO_GC_LENGTH (nbytes));
  44.   fast SCHEME_OBJECT result =
  45.     (allocate_non_marked_vector (TC_CHARACTER_STRING, count, true));
  46.   SET_STRING_LENGTH (result, nbytes);
  47.   return (result);
  48. }
  49.  
  50. SCHEME_OBJECT
  51. DEFUN (memory_to_string, (nbytes, data),
  52.        long nbytes
  53.        AND fast unsigned char * data)
  54. {
  55.   SCHEME_OBJECT result = (allocate_string (nbytes));
  56.   fast unsigned char * scan_result = (STRING_LOC (result, 0));
  57.   fast unsigned char * end_result = (scan_result + nbytes);
  58.   while (scan_result < end_result)
  59.     (*scan_result++) = (*data++);
  60.   return (result);
  61. }
  62.  
  63. SCHEME_OBJECT
  64. DEFUN (char_pointer_to_string, (char_pointer), unsigned char * char_pointer)
  65. {
  66.   unsigned char * scan = char_pointer;
  67.   if (scan == ((unsigned char *) NULL))
  68.     scan += 1;
  69.   else
  70.     while ((*scan++) != '\0')
  71.       ;
  72.   return (memory_to_string (((scan - 1) - char_pointer), char_pointer));
  73. }
  74.  
  75. /* Currently the strings used in symbols have type codes in the length
  76.    field.  They should be changed to have just longwords there. */
  77.  
  78. DEFINE_PRIMITIVE ("STRING-ALLOCATE", Prim_string_allocate, 1, 1, 0)
  79. {
  80.   PRIMITIVE_HEADER (1);
  81.   PRIMITIVE_RETURN (allocate_string (arg_nonnegative_integer (1)));
  82. }
  83.  
  84. DEFINE_PRIMITIVE ("STRING?", Prim_string_p, 1, 1, 0)
  85. {
  86.   PRIMITIVE_HEADER (1);
  87.   PRIMITIVE_RETURN (BOOLEAN_TO_OBJECT (STRING_P (ARG_REF (1))));
  88. }
  89.  
  90. DEFINE_PRIMITIVE ("STRING-LENGTH", Prim_string_length, 1, 1, 0)
  91. {
  92.   PRIMITIVE_HEADER (1);
  93.   CHECK_ARG (1, STRING_P);
  94.   PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (STRING_LENGTH (ARG_REF (1))));
  95. }
  96.  
  97. DEFINE_PRIMITIVE ("STRING-MAXIMUM-LENGTH", Prim_string_maximum_length, 1, 1, 0)
  98. {
  99.   PRIMITIVE_HEADER (1);
  100.   CHECK_ARG (1, STRING_P);
  101.   PRIMITIVE_RETURN
  102.     (LONG_TO_UNSIGNED_FIXNUM (MAXIMUM_STRING_LENGTH (ARG_REF (1))));
  103. }
  104.  
  105. DEFINE_PRIMITIVE ("SET-STRING-LENGTH!", Prim_set_string_length, 2, 2, 0)
  106. {
  107.   PRIMITIVE_HEADER (2);
  108.   CHECK_ARG (1, STRING_P);
  109.   {
  110.     fast SCHEME_OBJECT string = (ARG_REF (1));
  111.     SET_STRING_LENGTH
  112.       (string,
  113.        (arg_index_integer (2, ((MAXIMUM_STRING_LENGTH (string)) + 1))));
  114.   }
  115.   PRIMITIVE_RETURN (UNSPECIFIC);
  116. }
  117.  
  118. DEFINE_PRIMITIVE ("SET-STRING-MAXIMUM-LENGTH!", Prim_set_string_maximum_length, 2, 2, 0)
  119. {
  120.   PRIMITIVE_HEADER (2);
  121.   CHECK_ARG (1, STRING_P);
  122.   {
  123.     fast SCHEME_OBJECT string = (ARG_REF (1));
  124.     fast long length =
  125.       (arg_index_integer (2, ((MAXIMUM_STRING_LENGTH (string)) + 1)));
  126.     MEMORY_SET
  127.       (string,
  128.        STRING_HEADER,
  129.        (MAKE_OBJECT
  130.     (TC_MANIFEST_NM_VECTOR, ((BYTES_TO_WORDS (length + 1)) + 1))));
  131.     SET_STRING_LENGTH (string, length);
  132.   }
  133.   PRIMITIVE_RETURN (UNSPECIFIC);
  134. }
  135.  
  136. #define STRING_REF_BODY(process_result)                    \
  137. {                                    \
  138.   PRIMITIVE_HEADER (2);                            \
  139.   CHECK_ARG (1, STRING_P);                        \
  140.   {                                    \
  141.     fast SCHEME_OBJECT string = (ARG_REF (1));                \
  142.     PRIMITIVE_RETURN                            \
  143.       (process_result                            \
  144.        (STRING_REF                            \
  145.     (string, (arg_index_integer (2, (STRING_LENGTH (string)))))));    \
  146.   }                                    \
  147. }
  148.  
  149. DEFINE_PRIMITIVE ("STRING-REF", Prim_string_ref, 2, 2, 0)
  150.      STRING_REF_BODY (ASCII_TO_CHAR)
  151.  
  152. DEFINE_PRIMITIVE ("VECTOR-8B-REF", Prim_vec_8b_ref, 2, 2, 0)
  153.      STRING_REF_BODY (LONG_TO_UNSIGNED_FIXNUM)
  154.  
  155. #define STRING_SET_BODY(get_ascii)                    \
  156. {                                    \
  157.   PRIMITIVE_HEADER (3);                            \
  158.   CHECK_ARG (1, STRING_P);                        \
  159.   {                                    \
  160.     fast SCHEME_OBJECT string = (ARG_REF (1));                \
  161.     STRING_SET                                \
  162.       (string,                                \
  163.        (arg_index_integer (2, (STRING_LENGTH (string)))),        \
  164.        (get_ascii (3)));                        \
  165.   }                                    \
  166.   PRIMITIVE_RETURN (UNSPECIFIC);                    \
  167. }
  168.  
  169. DEFINE_PRIMITIVE ("STRING-SET!", Prim_string_set, 3, 3, 0)
  170.      STRING_SET_BODY (arg_ascii_char)
  171.  
  172. DEFINE_PRIMITIVE ("VECTOR-8B-SET!", Prim_vec_8b_set, 3, 3, 0)
  173.      STRING_SET_BODY (arg_ascii_integer)
  174.  
  175. #define SUBSTRING_MOVE_PREFIX()                        \
  176.   long start1, end1, start2, end2, length;                \
  177.   fast unsigned char *scan1, *scan2, *limit;                \
  178.   PRIMITIVE_HEADER (5);                            \
  179.   CHECK_ARG (1, STRING_P);                        \
  180.   start1 = (arg_nonnegative_integer (2));                \
  181.   end1 = (arg_nonnegative_integer (3));                    \
  182.   CHECK_ARG (4, STRING_P);                        \
  183.   start2 = (arg_nonnegative_integer (5));                \
  184.   length = (end1 - start1);                        \
  185.   end2 = (start2 + length);                        \
  186.   if (end1 > (STRING_LENGTH (ARG_REF (1))))                \
  187.     error_bad_range_arg (2);                        \
  188.   if (start1 > end1)                            \
  189.     error_bad_range_arg (1);                        \
  190.   if (end2 > (STRING_LENGTH (ARG_REF (4))))                \
  191.     error_bad_range_arg (3)
  192.  
  193. DEFINE_PRIMITIVE ("SUBSTRING-MOVE-RIGHT!", Prim_substring_move_right, 5, 5, 0)
  194. {
  195.   SUBSTRING_MOVE_PREFIX ();
  196.   scan1 = (STRING_LOC ((ARG_REF (1)), end1));
  197.   scan2 = (STRING_LOC ((ARG_REF (4)), end2));
  198.   limit = (scan1 - length);
  199.   while (scan1 > limit)
  200.     (*--scan2) = (*--scan1);
  201.   PRIMITIVE_RETURN (UNSPECIFIC);
  202. }
  203.  
  204. DEFINE_PRIMITIVE ("SUBSTRING-MOVE-LEFT!", Prim_substring_move_left, 5, 5, 0)
  205. {
  206.   SUBSTRING_MOVE_PREFIX ();
  207.   scan1 = (STRING_LOC ((ARG_REF (1)), start1));
  208.   scan2 = (STRING_LOC ((ARG_REF (4)), start2));
  209.   limit = (scan1 + length);
  210.   while (scan1 < limit)
  211.     (*scan2++) = (*scan1++);
  212.   PRIMITIVE_RETURN (UNSPECIFIC);
  213. }
  214.  
  215. #define SUBSTRING_MODIFIER(char_map)                    \
  216. {                                    \
  217.   SCHEME_OBJECT string;                            \
  218.   long start, end;                            \
  219.   fast long length;                            \
  220.   fast unsigned char *scan, temp;                    \
  221.   PRIMITIVE_HEADER (3);                            \
  222.   CHECK_ARG (1, STRING_P);                        \
  223.   string = (ARG_REF (1));                        \
  224.   start = (arg_nonnegative_integer (2));                \
  225.   end = (arg_nonnegative_integer (3));                    \
  226.   if (end > (STRING_LENGTH (string)))                    \
  227.     error_bad_range_arg (3);                        \
  228.   if (start > end)                            \
  229.     error_bad_range_arg (2);                        \
  230.   length = (end - start);                        \
  231.   scan = (STRING_LOC (string, start));                    \
  232.   while ((length--) > 0)                        \
  233.     {                                    \
  234.       temp = (*scan);                            \
  235.       (*scan++) = (char_map (temp));                    \
  236.     }                                    \
  237.   PRIMITIVE_RETURN (UNSPECIFIC);                    \
  238. }
  239.  
  240. DEFINE_PRIMITIVE ("SUBSTRING-UPCASE!", Prim_substring_upcase, 3, 3, 0)
  241.      SUBSTRING_MODIFIER (char_upcase)
  242.  
  243. DEFINE_PRIMITIVE ("SUBSTRING-DOWNCASE!", Prim_substring_downcase, 3, 3, 0)
  244.      SUBSTRING_MODIFIER (char_downcase)
  245.  
  246. #define VECTOR_8B_SUBSTRING_PREFIX()                    \
  247.   long start, end, ascii;                        \
  248.   fast unsigned char *string_start, *scan, *limit;            \
  249.   PRIMITIVE_HEADER (4);                            \
  250.   CHECK_ARG (1, STRING_P);                        \
  251.   string_start = (STRING_LOC ((ARG_REF (1)), 0));            \
  252.   start = (arg_nonnegative_integer (2));                \
  253.   end = (arg_nonnegative_integer (3));                    \
  254.   ascii = (arg_ascii_integer (4));                    \
  255.   if (end > (STRING_LENGTH (ARG_REF (1))))                \
  256.     error_bad_range_arg (3);                        \
  257.   if (start > end)                            \
  258.     error_bad_range_arg (2)
  259.  
  260. #define VECTOR_8B_SUBSTRING_PREFIX_FORWARD()                \
  261.   VECTOR_8B_SUBSTRING_PREFIX ();                    \
  262.   scan = (string_start + start);                    \
  263.   limit = (string_start + end);
  264.  
  265. #define VECTOR_8B_SUBSTRING_PREFIX_BACKWARD()                \
  266.   VECTOR_8B_SUBSTRING_PREFIX ();                    \
  267.   scan = (string_start + end);                        \
  268.   limit = (string_start + start);
  269.  
  270. DEFINE_PRIMITIVE ("VECTOR-8B-FILL!", Prim_vec_8b_fill, 4, 4, 0)
  271. {
  272.   VECTOR_8B_SUBSTRING_PREFIX_FORWARD ();
  273.   while (scan < limit)
  274.     (*scan++) = ascii;
  275.   PRIMITIVE_RETURN (UNSPECIFIC);
  276. }
  277.  
  278. DEFINE_PRIMITIVE ("VECTOR-8B-FIND-NEXT-CHAR", Prim_vec_8b_find_next_char, 4, 4, 0)
  279. {
  280.   VECTOR_8B_SUBSTRING_PREFIX_FORWARD ();
  281.   while (scan < limit)
  282.     if ((*scan++) == ascii)
  283.       PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM ((scan - 1) - string_start));
  284.   PRIMITIVE_RETURN (SHARP_F);
  285. }
  286.  
  287. DEFINE_PRIMITIVE ("VECTOR-8B-FIND-PREVIOUS-CHAR", Prim_vec_8b_find_prev_char, 4, 4, 0)
  288. {
  289.   VECTOR_8B_SUBSTRING_PREFIX_BACKWARD ();
  290.   while (scan > limit)
  291.     if ((*--scan) == ascii)
  292.       PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (scan - string_start));
  293.   PRIMITIVE_RETURN (SHARP_F);
  294. }
  295.  
  296. DEFINE_PRIMITIVE ("VECTOR-8B-FIND-NEXT-CHAR-CI", Prim_vec_8b_find_next_char_ci, 4, 4, 0)
  297. {
  298.   VECTOR_8B_SUBSTRING_PREFIX_FORWARD ();
  299.   {
  300.     fast unsigned char char1 = (char_upcase (ascii));
  301.     while (scan < limit)
  302.       if ((char_upcase (*scan++)) == char1)
  303.     PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM ((scan - 1) - string_start));
  304.   }
  305.   PRIMITIVE_RETURN (SHARP_F);
  306. }
  307.  
  308. DEFINE_PRIMITIVE ("VECTOR-8B-FIND-PREVIOUS-CHAR-CI", Prim_vec_8b_find_prev_char_ci, 4, 4, 0)
  309. {
  310.   VECTOR_8B_SUBSTRING_PREFIX_BACKWARD ();
  311.   {
  312.     fast unsigned char char1 = (char_upcase (ascii));
  313.     while (scan > limit)
  314.       if ((char_upcase (*--scan)) == char1)
  315.     PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (scan - string_start));
  316.   }
  317.   PRIMITIVE_RETURN (SHARP_F);
  318. }
  319.  
  320. #define SUBSTR_FIND_CHAR_IN_SET_PREFIX()                \
  321.   long start, end;                            \
  322.   unsigned char *char_set, *string_start, *scan, *limit;        \
  323.   PRIMITIVE_HEADER (4);                            \
  324.   CHECK_ARG (1, STRING_P);                        \
  325.   string_start = (STRING_LOC ((ARG_REF (1)), 0));            \
  326.   start = (arg_nonnegative_integer (2));                \
  327.   end = (arg_nonnegative_integer (3));                    \
  328.   CHECK_ARG (4, STRING_P);                        \
  329.   char_set = (STRING_LOC ((ARG_REF (4)), 0));                \
  330.   if (end > (STRING_LENGTH (ARG_REF (1))))                \
  331.     error_bad_range_arg (3);                        \
  332.   if (start > end)                            \
  333.     error_bad_range_arg (2);                        \
  334.   if ((STRING_LENGTH (ARG_REF (4))) != MAX_ASCII)            \
  335.     error_bad_range_arg (4)
  336.  
  337. DEFINE_PRIMITIVE ("SUBSTRING-FIND-NEXT-CHAR-IN-SET", Prim_find_next_char_in_set, 4, 4, 0)
  338. {
  339.   SUBSTR_FIND_CHAR_IN_SET_PREFIX ();
  340.   scan = (string_start + start);
  341.   limit = (string_start + end);
  342.   while (scan < limit)
  343.     if ((char_set [*scan++]) != '\0')
  344.       PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM ((scan - 1) - string_start));
  345.   PRIMITIVE_RETURN (SHARP_F);
  346. }
  347.  
  348. DEFINE_PRIMITIVE ("SUBSTRING-FIND-PREVIOUS-CHAR-IN-SET", Prim_find_prev_char_in_set, 4, 4, 0)
  349. {
  350.   SUBSTR_FIND_CHAR_IN_SET_PREFIX ();
  351.   scan = (string_start + end);
  352.   limit = (string_start + start);
  353.   while (scan > limit)
  354.     if ((char_set [*--scan]) != '\0')
  355.       PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (scan - string_start));
  356.   PRIMITIVE_RETURN (SHARP_F);
  357. }
  358.  
  359. #define SUBSTRING_COMPARE_PREFIX()                \
  360.   long start1, end1, start2, end2;                \
  361.   unsigned char *string1_start, *string2_start;            \
  362.   PRIMITIVE_HEADER (6);                        \
  363.   CHECK_ARG (1, STRING_P);                    \
  364.   string1_start = (STRING_LOC ((ARG_REF (1)), 0));        \
  365.   start1 = (arg_nonnegative_integer (2));            \
  366.   end1 = (arg_nonnegative_integer (3));                \
  367.   CHECK_ARG (4, STRING_P);                    \
  368.   string2_start = (STRING_LOC ((ARG_REF (4)), 0));        \
  369.   start2 = (arg_nonnegative_integer (5));            \
  370.   end2 = (arg_nonnegative_integer (6));                \
  371.   if (end1 > (STRING_LENGTH (ARG_REF (1))))            \
  372.     error_bad_range_arg (3);                    \
  373.   if (start1 > end1)                        \
  374.     error_bad_range_arg (2);                    \
  375.   if (end2 > (STRING_LENGTH (ARG_REF (4))))            \
  376.     error_bad_range_arg (6);                    \
  377.   if (start2 > end2)                        \
  378.     error_bad_range_arg (5)
  379.  
  380. #define SUBSTRING_EQUAL_PREFIX()                \
  381.   fast unsigned char *scan1, *scan2, *limit;            \
  382.   SUBSTRING_COMPARE_PREFIX ();                    \
  383.   if ((end1 - start1) != (end2 - start2))            \
  384.     PRIMITIVE_RETURN (SHARP_F);                    \
  385.   scan1 = (string1_start + start1);                \
  386.   limit = (string1_start + end1);                \
  387.   scan2 = (string2_start + start2)
  388.  
  389. DEFINE_PRIMITIVE ("SUBSTRING=?", Prim_substring_equal, 6, 6, 0)
  390. {
  391.   SUBSTRING_EQUAL_PREFIX ();
  392.   while (scan1 < limit)
  393.     if ((*scan1++) != (*scan2++))
  394.       PRIMITIVE_RETURN (SHARP_F);
  395.   PRIMITIVE_RETURN (SHARP_T);
  396. }
  397.  
  398. DEFINE_PRIMITIVE ("SUBSTRING-CI=?", Prim_substring_ci_equal, 6, 6, 0)
  399. {
  400.   SUBSTRING_EQUAL_PREFIX ();
  401.   while (scan1 < limit)
  402.     if ((char_upcase (*scan1++)) != (char_upcase (*scan2++)))
  403.       PRIMITIVE_RETURN (SHARP_F);
  404.   PRIMITIVE_RETURN (SHARP_T);
  405. }
  406.  
  407. DEFINE_PRIMITIVE ("SUBSTRING<?", Prim_substring_less, 6, 6, 0)
  408. {
  409.   SUBSTRING_COMPARE_PREFIX ();
  410.   {
  411.     fast unsigned char * scan1 = (string1_start + start1);
  412.     fast unsigned char * scan2 = (string2_start + start2);
  413.     long length1 = (end1 - start1);
  414.     long length2 = (end2 - start2);
  415.     fast unsigned char * limit =
  416.       (scan1 + ((length1 < length2) ? length1 : length2));
  417.     while (scan1 < limit)
  418.       if ((*scan1++) != (*scan2++))
  419.     PRIMITIVE_RETURN (BOOLEAN_TO_OBJECT ((scan1 [-1]) < (scan2 [-1])));
  420.     PRIMITIVE_RETURN (BOOLEAN_TO_OBJECT (length1 < length2));
  421.   }
  422. }
  423.  
  424. static long
  425. DEFUN (substring_length_min, (start1, end1, start2, end2),
  426.        long start1
  427.        AND long end1
  428.        AND long start2
  429.        AND long end2)
  430. {
  431.   fast long length1 = (end1 - start1);
  432.   fast long length2 = (end2 - start2);
  433.   return ((length1 < length2) ? length1 : length2);
  434. }
  435.  
  436. #define SUBSTRING_MATCH_PREFIX()                    \
  437.   fast unsigned char *scan1, *scan2, *limit;                \
  438.   long length;                                \
  439.   unsigned char *scan1_start;                        \
  440.   SUBSTRING_COMPARE_PREFIX ();                        \
  441.   length = (substring_length_min (start1, end1, start2, end2))
  442.  
  443. DEFINE_PRIMITIVE ("SUBSTRING-MATCH-FORWARD", Prim_match_forward, 6, 6, 0)
  444. {
  445.   SUBSTRING_MATCH_PREFIX ();
  446.   scan1 = (string1_start + start1);
  447.   scan2 = (string2_start + start2);
  448.   limit = (scan1 + length);
  449.   scan1_start = scan1;
  450.   while (scan1 < limit)
  451.     if ((*scan1++) != (*scan2++))
  452.       PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM ((scan1 - 1) - scan1_start));
  453.   PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (length));
  454. }
  455.  
  456. DEFINE_PRIMITIVE ("SUBSTRING-MATCH-FORWARD-CI", Prim_match_forward_ci, 6, 6, 0)
  457. {
  458.   SUBSTRING_MATCH_PREFIX ();
  459.   scan1 = (string1_start + start1);
  460.   scan2 = (string2_start + start2);
  461.   limit = (scan1 + length);
  462.   scan1_start = scan1;
  463.   while (scan1 < limit)
  464.     if ((char_upcase (*scan1++)) != (char_upcase (*scan2++)))
  465.       PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM ((scan1 - 1) - scan1_start));
  466.   PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (length));
  467. }
  468.  
  469. DEFINE_PRIMITIVE ("SUBSTRING-MATCH-BACKWARD", Prim_match_backward, 6, 6, 0)
  470. {
  471.   SUBSTRING_MATCH_PREFIX ();
  472.   scan1 = (string1_start + end1);
  473.   scan2 = (string2_start + end2);
  474.   limit = (scan1 - length);
  475.   scan1_start = scan1;
  476.   while (scan1 > limit)
  477.     if ((*--scan1) != (*--scan2))
  478.       PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (scan1_start - (scan1 + 1)));
  479.   PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (length));
  480. }
  481.  
  482. DEFINE_PRIMITIVE ("SUBSTRING-MATCH-BACKWARD-CI", Prim_match_backward_ci, 6, 6, 0)
  483. {
  484.   SUBSTRING_MATCH_PREFIX ();
  485.   scan1 = (string1_start + end1);
  486.   scan2 = (string2_start + end2);
  487.   limit = (scan1 - length);
  488.   scan1_start = scan1;
  489.   while (scan1 > limit)
  490.     if ((char_upcase (*--scan1)) != (char_upcase (*--scan2)))
  491.       PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (scan1_start - (scan1 + 1)));
  492.   PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (length));
  493. }
  494.